def Prost(h):
          h = int(h)
          r = 2
          while r < h:
                    if h % r == 0:
                              return False
                    else:
                              r += 1
          if r == h:
                    return True


g = input()
if len(g) != 4:
          print(0)
else:
          max_el = 0
          d = [g, g[1:3], g[1:], g[:3], g[0], g[1], g[2], g[3], g[2:], g[0:2]]
          for el in d:
               if int(el) > max_el and Prost(el):
                         max_el = int(el)
          print(max_el)
